Undefined Index ...confusion

Undefined Index ...confusion

am 23.07.2009 16:09:51 von tmiller

I keep getting this error while trying to use the field 'ID' to pass in a u=
rl.. And it's odd because the query is pulling everything BUT the ID which =
is the first field...

code:
=
"> $i]['name'])); ?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Undefined Index ...confusion

am 23.07.2009 16:24:07 von kyle.smith

--------------090208090806010507080602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Miller, Terion wrote:
> I keep getting this error while trying to use the field 'ID' to pass in a url.. And it's odd because the query is pulling everything BUT the ID which is the first field...
>
> code:
>

>
>
We're going to need to know how the $_SESSION['fullRestaurantList'] gets
populated. Also, where do you define $i? Is $i the ID? Seemed like
you've built an array of arrays and you may want
$_SESSION['fullRestaurantList'][$i]['ID'], or just $i. This is all
speculation from the 2 lines of code I've seen though.

- Kyle


--------------090208090806010507080602--

Re: Undefined Index ...confusion

am 23.07.2009 16:29:07 von Peter Ford

Miller, Terion wrote:
> I keep getting this error while trying to use the field 'ID' to pass in a url.. And it's odd because the query is pulling everything BUT the ID which is the first field...
>
> code:
>


What's the query?

I find (I use PostgreSQL rather than the mySQL that many on this list use) that
unless you explicitly ask for a field called ID (using SELECT "ID" ... ) you
get a returned field in lower case
So
$resource = pg_query("SELECT ID, Foo FROM MyTable WHERE Foo='Bar'");
$data = pg_fetch_all($resource)

gives me an array $data of rows like
$data[0]['id'] = '1'
$data[0]['foo'] = 'Bar'

To make sure $data[] has fields named ID and Foo I would have to do

$resource = pg_query("SELECT ID AS \"ID\", Foo AS \"Foo\" FROM MyTable WHERE
Foo='Bar'");


--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Undefined Index ...confusion

am 23.07.2009 16:29:30 von tmiller

On 7/23/09 9:24 AM, "Kyle Smith" wrote:

Miller, Terion wrote:

I keep getting this error while trying to use the field 'ID' to pass in a u=
rl.. And it's odd because the query is pulling everything BUT the ID which =
is the first field...

code:
=
"> $i]['name'])); ?>


We're going to need to know how the $_SESSION['fullRestaurantList'] gets po=
pulated. Also, where do you define $i? Is $i the ID? Seemed like you've =
built an array of arrays and you may want $_SESSION['fullRestaurantList'][$=
i]['ID'], or just $i. This is all speculation from the 2 lines of code I'v=
e seen though.

- Kyle



The full script is (I have my Entourage email settings on html so I hope th=
is displays ok for you all---seems I've been told it turns into a mess in s=
ome views) :

=
=
=
=
=
// Check if page is set to show all =
if(isset($_GET['show']) && $_GET['show'] == 'all') =
{ unset=
($_SESSION['results']); unset($_SESSIO=
N['searchname']); unset($_SESSION['add=
ress']); =
} =
// Check if there was an empty se=
arch sent if(isset($_SESSION['noVarsSent=
'])) { =
echo "

No values were submitted for the search.

"; =
// Unset it so a reload of page doesn't redisp=
lay the error unset($_SESSION['noVarsS=
ent']); // unset($_SESSION['results'])=
; } =
// C=
heck if full list of restaurants has been created and stored yet =
// Store full results in $_SESSION to limit databa=
se hits if(!isset($_SESSION['fullRestaur=
antList'])) { =
// List not grabbed yet, so run query and store in $_SESSION =
//che=
ck for range if (!(isset($rangenum))) =
{ $=
rangenum =3D 1; } =
// Grab all restaurants in alphabetical order =
$sql =3D "SELECT restaurants.ID, name, address, in=
Date, inType, notes, critical, cviolations, noncritical FROM restaurants, i=
nspections WHERE restaurants.name !=3D '' AND restaurants.ID =3D inspection=
s.ID ORDER BY name;"; $result =3D mys=
ql_query($sql) or die(mysql_error()); =
//trying to grab it by ranges from the db=
? $rows =3D mysql_num_rows($result)=
; $page_rows =3D 100; =
$last_row =3D ceil($rows/$page_rows); =
if ($rangenum < =
1) { =
$rangenum =3D 1; } =
elseif ($rangenum > $last_row) =
{ $rangenum =3D $last_row=
; } =
//This sets the range to display i=
n our query $max =3D 'limit ' .($range=
num - 1) * $page_rows .',' .$page_rows; =
=
// Process all results into $_SESS=
ION array =
$position =3D 1; =
while ($row =3D mysql_fetch_array($result)) =
{ $_S=
ESSION['fullRestaurantList'][$position] =3D $row; =
$position++; } =
$_SESSION['=
totalNumberOfRestaurants'] =3D $position; =
} =
?> =
=3D"5" width=3D"400" height=3D"180" valign=3D"top"> =

ws-leader.com/graphics/pixelclear.gif" width=3D"400" height=3D"1" /> =
=
=
=
right" height=3D"30">
Name:
=
hname" type=3D"text" size=3D"30" if(isset($_SESSION['searchname'])) =
{ echo " value=3D'" . $_S=
ESSION['searchname'] . "'"; } =
?> > =
=
=
=
ss=3D"admin_Caption">Address:
width=3D"80%"> N['address'])) { =
echo " value=3D'" . $_SESSION['address'] . "'"; =
} ?> =
> =
=
bmit" type=3D"submit" value=3D"Search">
/>
ll">Show all Restaurants

=
=
3">
=
=
if(isset($_GET['Page'])) =
$Page =3D $_GET['Page']; =
else $Page =3D 1; =
=
$Pe=
rPage =3D 30; if(isset($_SESSION['numResults']))=
{ $TotalPages =3D =
ceil($_SESSION['numResults']/$PerPage); } =
else { =
$TotalPages =3D 1; } =
$StartPage =3D ($Page - 1) * $PerPage;=
// Output table hea=
der ?> =
4"> D ALIGN=3D"CENTER" width=3D"50" VALIGN=3D"TOP" BGCOLOR=3D"#000000"> ze=3D"-2" COLOR=3D"#FFFFFF">Name =
=
=
=
> // Control logic to determine if displaying results or not=
if(isset($_SESSION['results'])) =
{ // Output results =
if($_SESSION['results'] == "=
No results found") { =
// Query came back with nothing ?> =
"> =
=
else { =
// There are results $ID=3D=
$_SESSION['results'][$i]['ID']; =
=
for($i =3D =
$StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['numResults']; $i++=
) { =
$color1 =3D "#FFFFFF"; =
$color2 =3D "#EAEAEA"; =
$row_color =3D ($i % 2) ? $color1 : $color2; =
?> p echo $row_color ?>"> =
=
=
=
=
=
} ?> =
000">Address BGCOLOR=3D"#000000">Inspection Date<=
/B>
=3D"20" VALIGN=3D"TOP" BGCOLOR=3D"#000000"> FF">Type ENTER" width=3D"120" VALIGN=3D"TOP" BGCOLOR=3D"#000000"> COLOR=3D"#FFFFFF">Notes size=3D"-2" COLOR=3D"#FFFFFF"># Critical Violations TOP" BGCOLOR=3D"#000000">Violations<=
/B>
th=3D"15" VALIGN=3D"TOP" BGCOLOR=3D"#000000"> FFFF"># Non-Critical

No resul=
ts where found matching your criteria.

=
>">=
; ?>
<=
?php echo stripslashes($_SESSION['results'][$i]['address']); ?>
es($_SESSION['results'][$i]['inDate']); ?> '][$i]['inType']); ?> SIZE=3D"-2"><=
/FONT>
stripslashes($_SESSION['results'][$i]['critical']); ?> SSION['results'][$i]['cviolations']); ?> sults'][$i]['noncritical']); ?>
} =
} else =
{ // No results, so output all re=
staurants sorted alphabetically =
=
// Else, list is already built. =
=
=
f=
or($i =3D $StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['totalNum=
berOfRestaurants']; $i++) { =
$color1 =3D "#FFFFFF"; =
$color2 =3D "#EAEAEA"; =
$row_color =3D ($i % 2) ? $color1 : $color=
2; ?> olor=3D""> NT SIZE=3D"-2"> tList']['ID']?>"> staurantList'][$i]['name'])); ?> =
antList'][$i]['address']); ?> =
'][$i]['inDate']); ?> T SIZE=3D"-2"> inType']); ?> =3D"-2"> ]); ?> ONT SIZE=3D"-2"> ['critical']); ?> IZE=3D"-2"> olations']); ?> =3D"center"> rantList'][$i]['noncritical']); ?> =
=
} ?> =
// Calculate total number of pages =
$TotalPages =3D ceil($_SESSION['totalNumberOfRestaur=
ants']/$PerPage); =
} =
// Output paging control // Only need =
to output this if there is more than 1 page of results =
if ($TotalPages > 1) { =
echo "
\n

Click on the fo=
llowing links for more pages of results

\n

"; =
if ($Page !=3D 1) =
{ // If on first page, no need for =
Previous Page button echo " rants.php?Page=3D"; echo $Page-1; =
echo "'><< Previous
"; =
} for($i =3D=
1; $i <=3D $TotalPages; $i++) { =
if($i == $Page) =
{ // Outputting =
link for current page - doesn't need to be a link =
echo "$i "; } =
else { =
// Outputting link for other pages - needs to be a link =
echo " "; =
} =
} =
if ($Page !=3D $TotalPages) { =
// If on last page, no need for Next Page button =
echo " echo $Page+1; echo "'>=
Next >>
"; } =
} =
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Undefined Index ...confusion

am 23.07.2009 16:34:31 von kyle.smith

--------------010906080706060900040801
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit



Miller, Terion wrote:
>
> On 7/23/09 9:24 AM, "Kyle Smith" wrote:
>
> Miller, Terion wrote:
>
> I keep getting this error while trying to use the field 'ID' to pass in a url.. And it's odd because the query is pulling everything BUT the ID which is the first field...
>
> code:
>
>
>
> We're going to need to know how the $_SESSION['fullRestaurantList'] gets populated. Also, where do you define $i? Is $i the ID? Seemed like you've built an array of arrays and you may want $_SESSION['fullRestaurantList'][$i]['ID'], or just $i. This is all speculation from the 2 lines of code I've seen though.
>
> - Kyle
>
>
>
> The full script is (I have my Entourage email settings on html so I hope this displays ok for you all---seems I've been told it turns into a mess in some views) :
>
>
It sure did turn into a big mess. Could you try using a pastebin
service? You should do this as a general best-practice anyway. Long
email threads tend to turn people off to helping you.

Go here:
http://pastebin.ca/

Paste your code and select "PHP" for Syntax Highlighting, then click
submit. You'll be given a short URL to share with the thread that will
bring us to an easy-to-read version of your code.

- Kyle

--------------010906080706060900040801--